/**
 * 
 */
/*导航栏是否已经隐藏*/
var navhiddened = false;
/*隐藏导航栏*/
var hiddennav = false;
/*全屏 */
var fullscreen = false;
/*预览*/
var onwatch = true;
var width = 0;
var height = 0;

function changeEditorSize() {
	if(fullscreen) {
		width = document.body.clientWidth - 40;
	} else {
		if(!hiddennav) {
			if(navhiddened) {
				width = document.body.clientWidth - 40;
			} else {
				width = document.body.clientWidth - 290;
			}
		} else {
			hiddennav = false;
		}
		height = document.body.clientHeight - 192;
	}
	console.log("width:" + width + " height:" + height);

	$(".m-form-content").width(width < 690 ? 690 : width);
	$(".m-input").width(width < 690 ? 690 : width - 40);

	$("#test-editormd").width(width < 690 ? 690 : width);
	$("#test-editormd").height(height);

	if(onwatch){
		$(".CodeMirror").width(width < 690 ? 345 : width / 2);
	}else{
		$(".CodeMirror").width(width < 690 ? 345 : width);
	}
	$(".CodeMirror").height(height);

	if(onwatch){
		$(".editormd-preview").width(width < 690 ? 345 : width / 2);
	}
	$(".editormd-preview").height(height);
}

$(document).ready(function() {

	/*开关:显示/隐藏导航栏*/
	$(".m-switch").click(function() {
		if($(".g-left").css("display") == "none") {
			$(".g-left").fadeIn(250);
			$(".g-right").css("width", "calc(100% - 250px)")
			navhiddened = false;
		} else {
			$(".g-left").fadeOut(250);
			$(".g-right").css("width", "100%");
			navhiddened = true;
			hiddennav = true;
			width = document.body.clientWidth - 20;
		}
		changeEditorSize();
	});
})